home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / By the Book / Learn C++ (CodeWarrior) / Chap 08.02 - stateBits / stateBits.cp < prev    next >
Text File  |  1995-10-21  |  559b  |  40 lines

  1. #include <iostream.h>
  2.  
  3. int    main()
  4. {
  5.     char    done = false;
  6.     char    c;
  7.     short    number;
  8.     
  9.     while ( ! done )
  10.     {
  11.         cout << "Type a number: ";
  12.         cin >> number;
  13.         
  14.         if ( cin.good() )
  15.         {
  16.             if ( number == 0 )
  17.             {
  18.                 cout << "Goodbye...";
  19.                 done = true;
  20.             }
  21.             else
  22.                 cout << "Your number is: " << number << "\n\n";
  23.         }
  24.         else if ( cin.fail() )
  25.         {
  26.             cin.clear();
  27.             
  28.             cin.get( c );
  29.             cout << c << " is not a number...";
  30.             cout << "Type 0 to exit\n\n";
  31.         }
  32.         else if ( cin.bad() )
  33.         {
  34.             cout << "\nYikes!!! Gotta go...";
  35.             done = true;
  36.         }
  37.     }
  38.     
  39.     return 0;
  40. }